package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.LocalBearingBusinessAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <Description> <br>
 *
 * @author cheng.leizhen01<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2021年3月16日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler <br>
 */
@Service
@AttrHandler(LocalBearingBusinessAttrHandler.class)
public class LocalBearingBusinessAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        if (Objects.isNull(attr)) {
            return;
        }
        KiteAttr ACustNameAttr = inst.getAttr("2_0000114");
        KiteAttr ZCustNameAttr = inst.getAttr("2_0000115");

        String opreatorProvinceNbr= ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr();
        //【河北】以太网新 承载业务属性，新增枚举值100004448【省内IPRAN】
        if(!KiteStringUtils.equals("18", opreatorProvinceNbr)) {
            attr.getAttrValues().removeIf(p -> KiteStringUtils.isEqual("100004448", p.getAttrValue()));
        } else {
            if(KiteStringUtils.equals("100004448", attr.getValue())){
                //AZ端客户名称为必填
                if(Objects.nonNull(ACustNameAttr)){
                    ACustNameAttr.setIsNull("F");
                }
                if(Objects.nonNull(ZCustNameAttr)){
                    ZCustNameAttr.setIsNull("F");
                }
            }else {
                if(Objects.nonNull(ACustNameAttr)){
                    ACustNameAttr.setIsNull("T");
                }
                if(Objects.nonNull(ZCustNameAttr)){
                    ZCustNameAttr.setIsNull("T");
                }
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }

}
